<?php

/**
 * midia actions.
 *
 * @package    sispatr
 * @subpackage midia
 * @author     Creatix
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class enderecoActions extends sfActionsCreatix
{

  public function executeCep()
  {
      $this->nu_cep      = $this->getRequestParameter("nu_cep");
      $cep         		 = new CEPLivreService();
      $result            = $cep->buscaEndereco($this->nu_cep);

      $result_array_to_json = array(
                            "sg_uf"         => $result->getUf(),
                            "estado"        => $result->getUfSigla(),
                            "logradouro"    => $result->getTipoLogradouroDesc(). " ". $result->getLogradouro(),
                            "bairro"        => $result->getBairro(),
                            "cidade"        => $result->getCidade(),

      );


      $this->getResponse()->setHttpHeader('Content-type','application/json; charset=utf-8');
      return $this->renderText(json_encode($result_array_to_json));
  }

  public function executeDelete(sfWebRequest $request)
  {
    try
    {
    $request->checkCSRFProtection();

    $this->forward404Unless($midia = Doctrine::getTable('Midia')->find(array($request->getParameter('id_midia'))), sprintf('Object midia does not exist (%s).', $request->getParameter('id_midia')));
    $midia->delete();

    $this->redirect('midia/index');
    }
    catch(Excepiton $e)
	{
		$this->getUser()->setFlash('erro', $e->getMessage());
    	$this->redirect('midia/index');
	}

  }
}
